class MyLinkedList2 // copy of MyLinkedList in Fig. 15.4 { private class Node ...
class MyLinkedList2 // copy of MyLinkedList in Fig. 15.4 { private class Node // inner class { private Node link; private int x; } //---------------------------------- private Node first = null; // initial value is null //---------------------------------- public void addFirst(int d) { Node newNode = new Node(); // create new node newNode.x = d; // init data field in new node newNode.link = first; // new node points to first node first = newNode; // first now points to new node } //---------------------------------- private void traverse(Node p) { if (p != null) { System.out.println(p.x); // display data traverse(p.link); // move p to next node } } public void traverse() { traverse(first); } public void reverseTest(); { Node p = first; if (p != null) { System.out.println(p.x); traverse(p.link); // move p to next node } } reverse(p); } //============================================== class TestMyLinkedList2 { public static void main(String[] args) { MyLinkedList2 list2 = new MyLinkedList2(); list2.addFirst(1); list2.addFirst(2); list2.addFirst(3); System.out.println("Numbers on list"); list2.traverse(); } }
11 years ago
999999.99
- A process of change
- soci111 help!
- A PROFESSIONAL WRITER NEEDED FOR ENGLISH !!
- com-231
- Define and discuss privatization and partnerships?
- The CompUSA e-Activity mentions that the Fiorentino brothers violated their "fiduciary responsibilities" to the company, which ultimately resulted in the company losing millions of dollars; however, one may question if there are ever legitimate business r
- "In the business world, the rear view mirror is always clearer than the windshield." Warren Buffett
- A-plus writer
- Electronic and engineering managment assignments
- Abitrage Risk mamangemnet 500 words